﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class update_student_detail : System.Web.UI.Page
{
    string Sno;

    protected void Page_Load(object sender, EventArgs e)
    {
        Sno=Request.QueryString["Sno"];
        Label1.Text = Sno;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string Sname = TextBox2.Text.Trim();
        string Sclass = TextBox3.Text.Trim();
        string Ssex = RadioButtonList1.Text.Trim();
        string Smajor = TextBox5.Text.Trim();
        string Syear = TextBox6.Text.Trim();

        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);


        try
        {
            if (string.IsNullOrEmpty(Sno) || string.IsNullOrEmpty(Sname) || string.IsNullOrEmpty(Sclass) || string.IsNullOrEmpty(Ssex) || string.IsNullOrEmpty(Smajor) || string.IsNullOrEmpty(Syear))
            {
                Response.Write("<h1>更新失败，学生的任一项信息不能为空！！</h1>");
            }
            else
            {

                connection.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = connection;

                string str_sql = "update Student set Sno='"+Sno+"',Sname='"+Sname+"',Sclass='"+Sclass+"',Ssex='"+Ssex+"',Smajor='"+Smajor+"',Syear='"+Syear+"' where Sno='"+Sno+"' ";
                comm.CommandText = str_sql;
                //comm.ExecuteScalar();  //如果为查询语句，则用ExecuteScalar()；否则，用ExecuteNonQuery()
                comm.ExecuteNonQuery();

                Response.Write("<h1>成功更新学生信息！</h1>");
            }
        }

        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        connection.Close();//关闭数据库连接
    }
}